from sqlalchemy import Column, DateTime, Enum, Float, ForeignKey, Integer, String, func
from sqlalchemy.orm import relationship

from app.bot.services.date_time import get_date_time
from app.database.models.base import Base


class Payment(Base):
    __tablename__ = "payment"

    id = Column(Integer, primary_key=True)
    summ = Column(Float, nullable=False)
    bill_id = Column(String(50))
    status = Column(
        Enum("paid", "waiting_payment", "payment_failed"),
        server_default="waiting_payment",
    )
    user_id = Column(Integer, ForeignKey("user.id"))
    user = relationship("User", back_populates="payments")
    created_at = Column(DateTime, server_default=func.now())

    def __repr__(self):
        return f"<Payment №{self.id} {self.summ}$>"

    def __str__(self):
        return self.__repr__()
